package com.b511.swpu.cementbackend.service.impl;

import com.b511.swpu.cementbackend.dto.input.ReportBaseDto;
import com.b511.swpu.cementbackend.dto.output.CMWKPiggingDto;
import com.b511.swpu.cementbackend.dto.output.generalReport.*;
import com.b511.swpu.cementbackend.dto.output.report.BwocOutputDto;
import com.b511.swpu.cementbackend.dto.output.report.ReportMaterialDto;
import com.b511.swpu.cementbackend.dto.output.report.ReportOutputDto;
import com.b511.swpu.cementbackend.dto.output.report.ReportSlurryOutputDto;
import com.b511.swpu.cementbackend.entity.*;
import com.b511.swpu.cementbackend.repository.*;
import com.b511.swpu.cementbackend.service.ReportGenerateService;
import com.b511.swpu.cementbackend.util.R;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DecimalFormat;
import java.util.*;

@Service
public class ReportGenerateServiceImpl implements ReportGenerateService {

    private final CM_WorkBaseInfoRepository cmWorkBaseInfoRepository;

    private final CM_WorkBasicRepository cmWorkBasicRepository;

    private final CM_WK_WorkRecordRepository cmWkWorkRecordRepository;

    private final CM_WK_AdditiveConsumeRepository cmWkAdditiveConsumeRepository;

    private final CM_WK_AccessoryConsumeRepository cmWkAccessoryConsumeRepository;

    private final CM_WK_MudPropertyRepository cmWkMudPropertyRepository;

    private final CM_WK_MudFormulaRepository cmWkMudFormulaRepository;

    private final CM_WK_DrillingRepository cmWkDrillingRepository;

    private final CM_WK_PiggingRepository cmWkPiggingRepository;

    private final CM_WK_FluidChangeRepository cmWkFluidChangeRepository;

    private final CM_WK_FluidPropertyRepository cmWkFluidPropertyRepository;

    private final CM_WK_LoggingTempRepository cmWkLoggingTempRepository;

    private final CM_WK_ThermometryRepository cmWkThermometryRepository;

    private final CM_WK_FormationPressureRepository cmWkFormationPressureRepository;

    private final CM_WK_TailCaseHangeRepository cmWkTailCaseHangeRepository;

    private final CM_WK_CirculationRepository cmWkCirculationRepository;

    private final CM_WK_CementFluidRepository cmWkCementFluidRepository;

    private final CM_WK_FluidFisrtRepository cmWkFluidFisrtRepository;

    private final CM_WK_FluidMiddleRepository cmWkFluidMiddleRepository;

    private final CM_WK_FluidLastRepository cmWkFluidLastRepository;

    private final CM_WK_DisplaceDataRepository cmWkDisplaceDataRepository;

    private final CM_WK_DisplaceRepository cmWkDisplaceRepository;

    private final CM_WK_ReturnFluidRepository cmWkReturnFluidRepository;

    private final CM_WK_TailClearRepository cmWkTailClearRepository;

    private final CM_WK_EmwRepository cmWkEmwRepository;

    private final CM_WK_ComplexRepository cmWkComplexRepository;

    private final CM_WK_FluidValueRepository cmWkFluidValueRepository;

    private final CM_WK_WellRejectRepository cmWkWellRejectRepository;

    public ReportGenerateServiceImpl(CM_WorkBaseInfoRepository cmWorkBaseInfoRepository,
                                     CM_WorkBasicRepository cmWorkBasicRepository,
                                     CM_WK_WorkRecordRepository cmWkWorkRecordRepository,
                                     CM_WK_AdditiveConsumeRepository cmWkAdditiveConsumeRepository,
                                     CM_WK_AccessoryConsumeRepository cmWkAccessoryConsumeRepository,
                                     CM_WK_MudPropertyRepository cmWkMudPropertyRepository,
                                     CM_WK_MudFormulaRepository cmWkMudFormulaRepository,
                                     CM_WK_DrillingRepository cmWkDrillingRepository,
                                     CM_WK_PiggingRepository cmWkPiggingRepository,
                                     CM_WK_FluidChangeRepository cmWkFluidChangeRepository,
                                     CM_WK_FluidPropertyRepository cmWkFluidPropertyRepository,
                                     CM_WK_LoggingTempRepository cmWkLoggingTempRepository,
                                     CM_WK_ThermometryRepository cmWkThermometryRepository,
                                     CM_WK_FormationPressureRepository cmWkFormationPressureRepository,
                                     CM_WK_TailCaseHangeRepository cmWkTailCaseHangeRepository,
                                     CM_WK_CirculationRepository cmWkCirculationRepository,
                                     CM_WK_CementFluidRepository cmWkCementFluidRepository,
                                     CM_WK_FluidFisrtRepository cmWkFluidFisrtRepository,
                                     CM_WK_FluidMiddleRepository cmWkFluidMiddleRepository,
                                     CM_WK_FluidLastRepository cmWkFluidLastRepository,
                                     CM_WK_DisplaceDataRepository cmWkDisplaceDataRepository,
                                     CM_WK_DisplaceRepository cmWkDisplaceRepository,
                                     CM_WK_ReturnFluidRepository cmWkReturnFluidRepository,
                                     CM_WK_TailClearRepository cmWkTailClearRepository,
                                     CM_WK_EmwRepository cmWkEmwRepository,
                                     CM_WK_ComplexRepository cmWkComplexRepository,
                                     CM_WK_WellRejectRepository cmWkWellRejectRepository,
                                     CM_WK_FluidValueRepository cmWkFluidValueRepository) {
        this.cmWorkBaseInfoRepository = cmWorkBaseInfoRepository;
        this.cmWorkBasicRepository = cmWorkBasicRepository;
        this.cmWkWorkRecordRepository = cmWkWorkRecordRepository;
        this.cmWkAdditiveConsumeRepository = cmWkAdditiveConsumeRepository;
        this.cmWkAccessoryConsumeRepository = cmWkAccessoryConsumeRepository;
        this.cmWkMudPropertyRepository = cmWkMudPropertyRepository;
        this.cmWkMudFormulaRepository = cmWkMudFormulaRepository;
        this.cmWkDrillingRepository = cmWkDrillingRepository;
        this.cmWkPiggingRepository = cmWkPiggingRepository;
        this.cmWkFluidChangeRepository = cmWkFluidChangeRepository;
        this.cmWkFluidPropertyRepository = cmWkFluidPropertyRepository;
        this.cmWkLoggingTempRepository = cmWkLoggingTempRepository;
        this.cmWkThermometryRepository = cmWkThermometryRepository;
        this.cmWkFormationPressureRepository = cmWkFormationPressureRepository;
        this.cmWkTailCaseHangeRepository = cmWkTailCaseHangeRepository;
        this.cmWkCirculationRepository = cmWkCirculationRepository;
        this.cmWkCementFluidRepository = cmWkCementFluidRepository;
        this.cmWkFluidFisrtRepository = cmWkFluidFisrtRepository;
        this.cmWkFluidMiddleRepository = cmWkFluidMiddleRepository;
        this.cmWkFluidLastRepository = cmWkFluidLastRepository;
        this.cmWkDisplaceDataRepository = cmWkDisplaceDataRepository;
        this.cmWkDisplaceRepository = cmWkDisplaceRepository;
        this.cmWkReturnFluidRepository = cmWkReturnFluidRepository;
        this.cmWkTailClearRepository = cmWkTailClearRepository;
        this.cmWkEmwRepository = cmWkEmwRepository;
        this.cmWkComplexRepository = cmWkComplexRepository;
        this.cmWkFluidValueRepository = cmWkFluidValueRepository;
        this.cmWkWellRejectRepository = cmWkWellRejectRepository;
    }

    @Override
    @Transactional
    public R getCasingSizeListByWellName(String wellName){

        List<CM_WorkBaseInfo> baseInfoList = cmWorkBaseInfoRepository.findByWellName(wellName);
        List<String> casingSizeDto = new ArrayList<>();
        for (CM_WorkBaseInfo tmp : baseInfoList){
            casingSizeDto.add(tmp.getCasingSize());
        }

        return R.ok().putData(casingSizeDto);
    }

    @Override
    @Transactional
    public R getCasingSizeListByWellNameFromWorkData(String wellName){

        List<CM_WK_BASIC> cm_wk_basicList=cmWorkBasicRepository.findWorkByWellName(wellName);
        List<String> casingSizeDto = new ArrayList<>();
        for (CM_WK_BASIC tmp : cm_wk_basicList){
            casingSizeDto.add(tmp.getCaseSize());
        }

        return R.ok().putData(casingSizeDto);

    }

    /*
    生成固井作业报表
     */
    @Override
    @Transactional
    public R getReportByWellNameAndCasingSize(String wellName, String casingSize) {
        // 作业类型 - 编号
        Map<String, String> tableType = new HashMap<String, String>() {
            {
                put("自升式-插入法固井", "1");
                put("自升式-套管固井-单级单封", "2");
                put("自升式-套管固井-单级双封", "3");
                put("自升式-套管固井-单一浆体", "4");
                put("自升式-尾管固井-领尾浆", "5");
                put("自升式-尾管固井-多浆体", "6");
                put("自升式-水泥塞", "7");
                put("半潜式-内管固井", "8");
                put("半潜式-套管固井-单级单封", "9");
                put("半潜式-套管固井-单级双封", "10");
                put("半潜式-套管固井-单一浆体", "11");
                put("半潜式-尾管固井-领尾浆", "12");
                put("半潜式-尾管固井-多浆体", "13");
                put("半潜式-水泥塞", "14");
                put("双级固井", "15");
                put("挤水泥", "16");
                put("尾管回接固井", "17");
            }
        };

        // 返回的dto
        ReportOutputDto outputDto = new ReportOutputDto();

        // TODO: 生成基本数据 CM_WK_BASIC
        // 2020.11.3 此处查询应该使用 wellName 和 caseSize 一起查，未考虑到同一井名下，多个套管的情况
        CM_WK_BASIC tmpBasic = cmWorkBasicRepository.findByWellNameAndCaseSize(wellName, casingSize);
        if(null == tmpBasic){
            return R.ok().putData(outputDto);
        }

        if (null != tmpBasic) {
            outputDto.setBasic(tmpBasic);
        }
        // TODO: 通过 reportType 判断固井报告的模板
        String workType = tmpBasic.getReportType();

        if (true == tableType.containsKey(workType)){
            outputDto.setTableId(tableType.get(workType));
        }else{
            return R.error().putData("请检查CM_WK_BASIC中报表类型字段!");
        }

        // TODO: 生成水泥浆化验数据
        ReportSlurryOutputDto slurryOutputDto = new ReportSlurryOutputDto();
        // 查询作业水泥浆性能
        List<CM_WK_MudProperty> mudProperties = cmWkMudPropertyRepository.findByWellNameAndCasingSize(wellName, casingSize);
        if (0 != mudProperties.size()){
            slurryOutputDto.setMudProperties(mudProperties);
        }
        // 查询作业水泥浆配方
        // 不重复的materialName
        Set<String> materialNameSet = new HashSet<>();
        // 构建 BWOC
        List<BwocOutputDto> bwoc = new ArrayList<>();
        List<CM_WK_MudFormula> mudFormulas = cmWkMudFormulaRepository.findByWellNameAndCasingSize(wellName, casingSize);
        // materialName去重
        for (CM_WK_MudFormula tmpFormula : mudFormulas){
            materialNameSet.add(tmpFormula.getMaterialName());
        }

        // 构造List
        if (0 != mudFormulas.size()){
            for( String curName : materialNameSet ){
                BwocOutputDto tmpBwoc = new BwocOutputDto();
                // init field at here
                tmpBwoc.setMaterialName(curName);
                tmpBwoc.setFirstHead("");
                tmpBwoc.setFirstTail("");
                tmpBwoc.setSecondHead("");
                tmpBwoc.setSecondTail("");

                for (CM_WK_MudFormula tmpFormula : mudFormulas){
                    if (curName.equals(tmpFormula.getMaterialName())){
                        String expItem = tmpFormula.getExprementItem();
                        Integer itemNo = tmpFormula.getItemNo();
                        String usage = tmpFormula.getMaterialDosage();
                        // exprementItem = 领浆 && itemNo = 1 -> 领浆1
                        if ("领浆".equals(expItem) && itemNo == 1){
                            tmpBwoc.setFirstHead(usage);
                        }
                        // exprementItem = 尾浆 && itemNo = 1 -> 尾浆1
                        if ("尾浆".equals(expItem) && itemNo == 1){
                            tmpBwoc.setFirstTail(usage);
                        }
                        // exprementItem = 领浆 && itemNo = 2 -> 领浆2
                        if ("领浆".equals(expItem) && itemNo ==2){
                            tmpBwoc.setSecondHead(usage);
                        }
                        // exprementItem = 尾浆 && itemNo = 2 -> 尾浆2
                        if ("尾浆".equals(expItem) && itemNo == 2){
                            tmpBwoc.setSecondTail(usage);
                        }
                    }
                }
                bwoc.add(tmpBwoc);
            }
        }

        slurryOutputDto.setBwoc(bwoc);
        outputDto.setMudData(slurryOutputDto);

        // TODO: 生成施工数据
        List<CM_WK_WorkRecord> workRecords = cmWkWorkRecordRepository.findByWellNameAndCasingSizeOrderByWorkNoAsc(wellName, casingSize);
        if (0 != workRecords.size()){
            outputDto.setWorkData(workRecords);
        }

        // TODO: 生成材料消耗数据
        ReportMaterialDto materialDto = new ReportMaterialDto();
        // 查询添加剂消耗
        List<CM_WK_AdditiveConsume> additiveConsumes = cmWkAdditiveConsumeRepository.findByWellNameAndCasingSize(wellName, casingSize);
        if (0 != additiveConsumes.size()){
            materialDto.setAdditives(additiveConsumes);
        }
        // 查询附件消耗
        List<CM_WK_AccessoryConsume> accessoryConsumes = cmWkAccessoryConsumeRepository.findByWellNameAndCasingSize(wellName, casingSize);
        if (0 != accessoryConsumes.size()){
            materialDto.setAccessories(accessoryConsumes);
        }
        outputDto.setMaterial(materialDto);

        return R.ok().putData(outputDto);
    }

    /*
     * 生成固井综合数据报表
     * Param: List<ReportBaseDto>
     *
     */
    @Override
    @Transactional
    public R getGeneralDataReportByWellNameAndCasingSize(List<ReportBaseDto> inputDto){
        /**
         * 接收 List<String wellName, String casingSize> inputDto
         * 解析 inputDto，生成 Json
         */
        // 实际返回形式为 List<GeneralReportOutputDto>
        List<GeneralReportOutputDto> output = new ArrayList<>();

        // TODO: fix bug: 如果数据库存在多条数据，如何只取一条？
        for (ReportBaseDto tmpInput : inputDto){
            GeneralReportOutputDto tmpOutput = new GeneralReportOutputDto();
            // 0.井名 & 套管尺寸
            String tmpWellName = tmpInput.getWellName();
            String tmpCasingSize = tmpInput.getCasingSize();

            // 1. 基本数据
            CM_WK_BASIC tmpBasic = cmWorkBasicRepository.findByWellNameAndCaseSize(tmpWellName, tmpCasingSize);
            tmpOutput.setBasic(tmpBasic);

            // 2.钻井情况
            Optional<CM_WK_Drilling> drillingOpt = cmWkDrillingRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (drillingOpt.isPresent()){
                tmpOutput.setDrilling(drillingOpt.get());
            }

            // 3.通井情况
            Optional<CM_WK_Pigging> piggingOpt = cmWkPiggingRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (piggingOpt.isPresent()){
                Double drillPipeAV = piggingOpt.get().getDrillPipeAV();
                DecimalFormat df = new DecimalFormat("#0.000");
                String temp = df.format(drillPipeAV);
                System.out.println(temp);
                CMWKPiggingDto cmwkPiggingDto = new CMWKPiggingDto();
                cmwkPiggingDto.setCM_WK_Pigging_ID(piggingOpt.get().getCM_WK_Pigging_ID());
                cmwkPiggingDto.setCasingSize(piggingOpt.get().getCasingSize());
                cmwkPiggingDto.setPiggingMaxDisplacement(piggingOpt.get().getPiggingMaxDisplacement());
                cmwkPiggingDto.setMaxTotalGas(piggingOpt.get().getMaxTotalGas());
                cmwkPiggingDto.setEndTotalGas(piggingOpt.get().getEndTotalGas());
                cmwkPiggingDto.setGasChannelingVelocity(piggingOpt.get().getGasChannelingVelocity());
                cmwkPiggingDto.setDrillPipeAV(temp);
                cmwkPiggingDto.setDrillCollarAV(piggingOpt.get().getDrillCollarAV());
                cmwkPiggingDto.setComplexDescription(piggingOpt.get().getComplexDescription());
                tmpOutput.setPigging(cmwkPiggingDto);
            }

            // 4.泥浆转换深度
            Optional<CM_WK_FluidChange> fluidChangeOpt = cmWkFluidChangeRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (fluidChangeOpt.isPresent()){
                tmpOutput.setFluidChange(fluidChangeOpt.get());
            }

            // 5.泥浆性能（调整前后）
            FluidPropertyOutputDto fluidPropertyDto = new FluidPropertyOutputDto();
            List<CM_WK_FluidProperty> fluidProperties = cmWkFluidPropertyRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            for (int i = 0; i < fluidProperties.size(); i++) {
                System.out.println("泥浆性能 Size=" + fluidProperties.size());
                //不断相加
                if (i == 0) {
                    fluidPropertyDto.setCementStatus("" + (StringUtils.isNotBlank(fluidProperties.get(i).getCementStatus())
                            ? fluidProperties.get(i).getCementStatus() : "-" ));
                    fluidPropertyDto.setFluidType("" + (StringUtils.isNotBlank(fluidProperties.get(i).getFluidType())
                            ? fluidProperties.get(i).getFluidType() : "-" ));
                    fluidPropertyDto.setDensity("" + (fluidProperties.get(i).getDensity()!=null
                            ? fluidProperties.get(i).getDensity() : "-" ));
                    fluidPropertyDto.setFV("" + (fluidProperties.get(i).getFV()!=null
                            ? fluidProperties.get(i).getFV() : "-" ));
                    fluidPropertyDto.setAV("" + (fluidProperties.get(i).getAV()!=null
                            ? fluidProperties.get(i).getAV() : "-" ));
                    fluidPropertyDto.setYP("" + (fluidProperties.get(i).getYP()!=null
                            ? fluidProperties.get(i).getYP() : "-" ));
                    fluidPropertyDto.setGel10S("" + (fluidProperties.get(i).getGEL10S()!=null
                            ? fluidProperties.get(i).getGEL10S() : "-" ));
                    fluidPropertyDto.setGel10M("" + (fluidProperties.get(i).getGEL10M()!=null
                            ? fluidProperties.get(i).getGEL10M() : "-" ));
                    fluidPropertyDto.setRpm3("" + (fluidProperties.get(i).getRPM3()!=null
                            ? fluidProperties.get(i).getRPM3() : "-" ));
                    fluidPropertyDto.setRpm6("" + (fluidProperties.get(i).getRPM6()!=null
                            ? fluidProperties.get(i).getRPM6() : "-" ));
                    fluidPropertyDto.setRpm100("" + (fluidProperties.get(i).getRPM100()!=null
                            ? fluidProperties.get(i).getRPM100() : "-" ));
                    fluidPropertyDto.setRpm200("" + (fluidProperties.get(i).getRPM200()!=null
                            ? fluidProperties.get(i).getRPM200() : "-" ));
                    fluidPropertyDto.setRpm300("" + (fluidProperties.get(i).getRPM300()!=null
                            ? fluidProperties.get(i).getRPM300() : "-" ));
                    fluidPropertyDto.setRpm600("" + (fluidProperties.get(i).getRPM600()!=null
                            ? fluidProperties.get(i).getRPM600() : "-" ));
                } else {
                    fluidPropertyDto.setCementStatus(fluidPropertyDto.getCementStatus() + " & " + (StringUtils.isNotBlank(fluidProperties.get(i).getCementStatus())
                            ? fluidProperties.get(i).getCementStatus() : "-" ));
                    fluidPropertyDto.setFluidType(fluidPropertyDto.getFluidType() + " & " + (StringUtils.isNotBlank(fluidProperties.get(i).getFluidType())
                            ? fluidProperties.get(i).getFluidType() : "-" ));
                    fluidPropertyDto.setDensity(fluidPropertyDto.getDensity() + " & " + (fluidProperties.get(i).getDensity()!=null
                            ? fluidProperties.get(i).getDensity() : "-" ));
                    fluidPropertyDto.setFV(fluidPropertyDto.getFV() + " & " + (fluidProperties.get(i).getFV()!=null
                            ? fluidProperties.get(i).getFV() : "-" ));
                    fluidPropertyDto.setAV(fluidPropertyDto.getAV() + " & " + (fluidProperties.get(i).getAV()!=null
                            ? fluidProperties.get(i).getAV() : "-" ));
                    fluidPropertyDto.setYP(fluidPropertyDto.getYP() + " & " + (fluidProperties.get(i).getYP()!=null
                            ? fluidProperties.get(i).getYP() : "-" ));
                    fluidPropertyDto.setGel10S(fluidPropertyDto.getGel10S() + " & " + (fluidProperties.get(i).getGEL10S()!=null
                            ? fluidProperties.get(i).getGEL10S() : "-" ));
                    fluidPropertyDto.setGel10M(fluidPropertyDto.getGel10M() + " & " + (fluidProperties.get(i).getGEL10M()!=null
                            ? fluidProperties.get(i).getGEL10M() : "-" ));
                    fluidPropertyDto.setRpm3(fluidPropertyDto.getRpm3() + " & " + (fluidProperties.get(i).getRPM3()!=null
                            ? fluidProperties.get(i).getRPM3() : "-" ));
                    fluidPropertyDto.setRpm6(fluidPropertyDto.getRpm6() + " & " + (fluidProperties.get(i).getRPM6()!=null
                            ? fluidProperties.get(i).getRPM6() : "-" ));
                    fluidPropertyDto.setRpm100(fluidPropertyDto.getRpm100() + " & " + (fluidProperties.get(i).getRPM100()!=null
                            ? fluidProperties.get(i).getRPM100() : "-" ));
                    fluidPropertyDto.setRpm200(fluidPropertyDto.getRpm200() + " & " + (fluidProperties.get(i).getRPM200()!=null
                            ? fluidProperties.get(i).getRPM200() : "-" ));
                    fluidPropertyDto.setRpm300(fluidPropertyDto.getRpm300() + " & " + (fluidProperties.get(i).getRPM300()!=null
                            ? fluidProperties.get(i).getRPM300() : "-" ));
                    fluidPropertyDto.setRpm600(fluidPropertyDto.getRpm600() + " & " + (fluidProperties.get(i).getRPM600()!=null
                            ? fluidProperties.get(i).getRPM600() : "-" ));
                }
            }
            tmpOutput.setFluidProperty(fluidPropertyDto);

            // 6.电测温度
            Optional<CM_WK_LoggingTemp> loggingTempOpt = cmWkLoggingTempRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (loggingTempOpt.isPresent()){
                tmpOutput.setLogging(loggingTempOpt.get());
            }

            // 7.随钻工具测温
            Optional<CM_WK_Thermometry> thermometryOpt = cmWkThermometryRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (thermometryOpt.isPresent()){
                tmpOutput.setThermometry(thermometryOpt.get());
            }

            // 8.地层压力数据
            Optional<CM_WK_FormationPressure> formationPressureOpt = cmWkFormationPressureRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (formationPressureOpt.isPresent()){
                tmpOutput.setFormationPressure(formationPressureOpt.get());
            }

            // 9.水泥浆化验数据
            // 需要拼接
            MudPropertyOutputDto mudPropertyOutputDto = new MudPropertyOutputDto();
            List<CM_WK_MudProperty> mudProperties = cmWkMudPropertyRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            System.out.println("水泥浆化验 Size=" + mudProperties.size());
            for (int i = 0; i < mudProperties.size(); i++) {
                //不断相加
                if ( i == 0){
                    mudPropertyOutputDto.setExperimentItem("" + (StringUtils.isNotBlank(mudProperties.get(i).getExprementItem())
                                    ? mudProperties.get(i).getExprementItem() : "-" ));
                    mudPropertyOutputDto.setFluidType("" + (StringUtils.isNotBlank(mudProperties.get(i).getFluidType())
                                    ? mudProperties.get(i).getFluidType() : "-" ));
                    mudPropertyOutputDto.setItemNo("" + (StringUtils.isNotBlank(mudProperties.get(i).getItemNo().toString())
                                    ? mudProperties.get(i).getItemNo().toString() : "-" ));
                    mudPropertyOutputDto.setMudType("" + (StringUtils.isNotBlank(mudProperties.get(i).getMudType())
                                    ? mudProperties.get(i).getMudType() : "-" ));
                    mudPropertyOutputDto.setCL("" + (StringUtils.isNotBlank(mudProperties.get(i).getCl())
                                    ? mudProperties.get(i).getCl() : "-" ));
                    mudPropertyOutputDto.setStopTemperature("" + (mudProperties.get(i).getStopTemperature()!=null
                            ? mudProperties.get(i).getStopTemperature() : "-" ));
                    mudPropertyOutputDto.setRecyleTemperature("" + (mudProperties.get(i).getRecyleTemperature()!=null
                            ? mudProperties.get(i).getRecyleTemperature() : "-" ));
                    mudPropertyOutputDto.setHolePressure("" + (mudProperties.get(i).getHolePressure()!=null
                                    ? mudProperties.get(i).getHolePressure() : "-" ));
                    mudPropertyOutputDto.setThickTime("" + (StringUtils.isNotBlank(mudProperties.get(i).getThickengTime())
                                    ? mudProperties.get(i).getThickengTime() : "-" ));
                    mudPropertyOutputDto.setMudDensity("" + (StringUtils.isNotBlank(mudProperties.get(i).getMudDensity())
                                    ? mudProperties.get(i).getMudDensity() : "-" ));
                    mudPropertyOutputDto.setMudYield("" + (mudProperties.get(i).getMudYield()!=null
                                    ? mudProperties.get(i).getMudYield() : "-" ));
                    mudPropertyOutputDto.setWaterCementRatio("" + (mudProperties.get(i).getWaterCementRatio()!=null
                                    ? mudProperties.get(i).getWaterCementRatio() : "-" ));
                    mudPropertyOutputDto.setApiLossWater("" + (mudProperties.get(i).getApiFluidLoss()!=null
                                    ? mudProperties.get(i).getApiFluidLoss() : "-" ));
                    mudPropertyOutputDto.setFreeWater("" + (mudProperties.get(i).getFreeWater()!=null
                                    ? mudProperties.get(i).getFreeWater() : "-" ));
                    mudPropertyOutputDto.setPressure24("" + (mudProperties.get(i).getPressure24()!=null
                                    ? mudProperties.get(i).getPressure24() : "-" ));

                    System.out.println("i=0:");
                    System.out.println(mudPropertyOutputDto);

                }else{
                    mudPropertyOutputDto.setExperimentItem(mudPropertyOutputDto.getExperimentItem() + " & " + (StringUtils.isNotBlank(mudProperties.get(i).getExprementItem())
                                    ? mudProperties.get(i).getExprementItem() : "-" ));
                    mudPropertyOutputDto.setFluidType(mudPropertyOutputDto.getFluidType() + " & " + (StringUtils.isNotBlank(mudProperties.get(i).getFluidType())
                            ? mudProperties.get(i).getFluidType() : "-" ));
                    mudPropertyOutputDto.setItemNo(mudPropertyOutputDto.getItemNo() + " & " + (StringUtils.isNotBlank(mudProperties.get(i).getItemNo().toString())
                            ? mudProperties.get(i).getItemNo().toString() : "-" ));
                    mudPropertyOutputDto.setMudType(mudPropertyOutputDto.getMudType() + " & " + (StringUtils.isNotBlank(mudProperties.get(i).getMudType())
                            ? mudProperties.get(i).getMudType() : "-" ));
                    mudPropertyOutputDto.setCL(mudPropertyOutputDto.getCL() + " & " + (StringUtils.isNotBlank(mudProperties.get(i).getCl())
                            ? mudProperties.get(i).getCl() : "-" ));
                    mudPropertyOutputDto.setStopTemperature(mudPropertyOutputDto.getStopTemperature() + " & " + (mudProperties.get(i).getStopTemperature()!=null
                            ? mudProperties.get(i).getStopTemperature() : "-" ));
                    mudPropertyOutputDto.setRecyleTemperature(mudPropertyOutputDto.getRecyleTemperature() + " & " + (mudProperties.get(i).getRecyleTemperature()!=null
                            ? mudProperties.get(i).getRecyleTemperature() : "-" ));
                    mudPropertyOutputDto.setHolePressure(mudPropertyOutputDto.getHolePressure() + " & " + (mudProperties.get(i).getHolePressure()!=null
                            ? mudProperties.get(i).getHolePressure() : "-" ));
                    mudPropertyOutputDto.setThickTime(mudPropertyOutputDto.getThickTime() + " & " + (StringUtils.isNotBlank(mudProperties.get(i).getThickengTime())
                            ? mudProperties.get(i).getThickengTime() : "-" ));
                    mudPropertyOutputDto.setMudDensity(mudPropertyOutputDto.getMudDensity() + " & " + (StringUtils.isNotBlank(mudProperties.get(i).getMudDensity())
                            ? mudProperties.get(i).getMudDensity() : "-" ));
                    mudPropertyOutputDto.setMudYield(mudPropertyOutputDto.getMudYield() + " & " + (mudProperties.get(i).getMudYield()!=null
                            ? mudProperties.get(i).getMudYield() : "-" ));
                    mudPropertyOutputDto.setWaterCementRatio(mudPropertyOutputDto.getWaterCementRatio() + " & " + (mudProperties.get(i).getWaterCementRatio()!=null
                            ? mudProperties.get(i).getWaterCementRatio() : "-" ));
                    mudPropertyOutputDto.setApiLossWater(mudPropertyOutputDto.getApiLossWater() + " & " + (mudProperties.get(i).getApiFluidLoss()!=null
                            ? mudProperties.get(i).getApiFluidLoss() : "-" ));
                    mudPropertyOutputDto.setFreeWater(mudPropertyOutputDto.getFreeWater() + " & " + (mudProperties.get(i).getFreeWater()!=null
                            ? mudProperties.get(i).getFreeWater() : "-" ));
                    mudPropertyOutputDto.setPressure24(mudPropertyOutputDto.getPressure24() + " & " + (mudProperties.get(i).getPressure24()!=null
                            ? mudProperties.get(i).getPressure24() : "-" ));

                    System.out.println("i=:" + i);
                    System.out.println(mudPropertyOutputDto);
                }
            }
            tmpOutput.setMudProperty(mudPropertyOutputDto);

            // 10.油层位置


            // 11.特殊层


            // 12.尾管挂
            Optional<CM_WK_TailCaseHange> tailCaseHangeOpt = cmWkTailCaseHangeRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (tailCaseHangeOpt.isPresent()){
                tmpOutput.setTailCaseHange(tailCaseHangeOpt.get());
            }

            // 13.固井前循环
            Optional<CM_WK_Circulation> circulationOpt = cmWkCirculationRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (circulationOpt.isPresent()){
                tmpOutput.setCirculation(circulationOpt.get());
            }

            // 14.固井流体数据冲洗液与隔离液 需要拼接
            CementFluidOutputDto cementFluidDto = new CementFluidOutputDto();
            List<CM_WK_CementFluid> cementFluids = cmWkCementFluidRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            for (int i = 0; i < cementFluids.size(); i++) {
                //不断相加
                if (i == 0) {
                    cementFluidDto.setFluidType("" + (StringUtils.isNotBlank(cementFluids.get(i).getFluidType())
                            ? cementFluids.get(i).getFluidType() : "-" ));
                    cementFluidDto.setFormula("" + (StringUtils.isNotBlank(cementFluids.get(i).getFormula())
                                    ? cementFluids.get(i).getFormula() : "-" ));
                    cementFluidDto.setDensity("" + (cementFluids.get(i).getDensity() !=null
                                    ? cementFluids.get(i).getDensity() : "-" ));
                    cementFluidDto.setRpm3("" + (cementFluids.get(i).getRpm3() !=null
                                    ? cementFluids.get(i).getRpm3() : "-" ));
                    cementFluidDto.setRpm6("" + (cementFluids.get(i).getRpm6() !=null
                                    ? cementFluids.get(i).getRpm6() : "-" ));
                    cementFluidDto.setRpm100("" + (cementFluids.get(i).getRpm100() !=null
                                    ? cementFluids.get(i).getRpm100() : "-" ));
                    cementFluidDto.setRpm200("" + (cementFluids.get(i).getRpm200() !=null
                                    ? cementFluids.get(i).getRpm200() : "-" ));
                    cementFluidDto.setRpm300("" + (cementFluids.get(i).getRpm300() !=null
                                    ? cementFluids.get(i).getRpm300() : "-" ));
                    cementFluidDto.setRpm600("" + (cementFluids.get(i).getRpm600() !=null
                                    ? cementFluids.get(i).getRpm600() : "-" ));
                    cementFluidDto.setFV1("" + (cementFluids.get(i).getFv1() !=null
                                    ? cementFluids.get(i).getFv1() : "-" ));
                    cementFluidDto.setFV2("" + (cementFluids.get(i).getFv2() !=null
                                    ? cementFluids.get(i).getFv2() : "-" ));
                    cementFluidDto.setInjectVol("" + (cementFluids.get(i).getInjectVol() !=null
                                    ? cementFluids.get(i).getInjectVol() : "-" ));
                    cementFluidDto.setIsolatedWaterVol("" + (cementFluids.get(i).getIsolatedWaterVol() !=null
                                    ? cementFluids.get(i).getIsolatedWaterVol() : "-" ));
                }else{
                    cementFluidDto.setFluidType(cementFluidDto.getFluidType() + " & " + (StringUtils.isNotBlank(cementFluids.get(i).getFluidType())
                            ? cementFluids.get(i).getFluidType() : "-" ));
                    cementFluidDto.setFormula(cementFluidDto.getFormula() + " & " + (StringUtils.isNotBlank(cementFluids.get(i).getFormula())
                            ? cementFluids.get(i).getFormula() : "-" ));
                    cementFluidDto.setDensity(cementFluidDto.getDensity() + " & " + (cementFluids.get(i).getDensity() !=null
                            ? cementFluids.get(i).getDensity() : "-" ));
                    cementFluidDto.setRpm3(cementFluidDto.getRpm3() + " & "  + (cementFluids.get(i).getRpm3() !=null
                            ? cementFluids.get(i).getRpm3() : "-" ));
                    cementFluidDto.setRpm6(cementFluidDto.getRpm6() + " & "  + (cementFluids.get(i).getRpm6() !=null
                            ? cementFluids.get(i).getRpm6() : "-" ));
                    cementFluidDto.setRpm100(cementFluidDto.getRpm100() + " & "  + (cementFluids.get(i).getRpm100() !=null
                            ? cementFluids.get(i).getRpm100() : "-" ));
                    cementFluidDto.setRpm200(cementFluidDto.getRpm200() + " & "  + (cementFluids.get(i).getRpm200() !=null
                            ? cementFluids.get(i).getRpm200() : "-" ));
                    cementFluidDto.setRpm300(cementFluidDto.getRpm300() + " & "  + (cementFluids.get(i).getRpm300() !=null
                            ? cementFluids.get(i).getRpm300() : "-" ));
                    cementFluidDto.setRpm600(cementFluidDto.getRpm600() + " & "  + (cementFluids.get(i).getRpm600() !=null
                            ? cementFluids.get(i).getRpm600() : "-" ));
                    cementFluidDto.setFV1(cementFluidDto.getFV1() + " & "  + (cementFluids.get(i).getFv1() !=null
                            ? cementFluids.get(i).getFv1() : "-" ));
                    cementFluidDto.setFV2(cementFluidDto.getFV2() + " & "  + (cementFluids.get(i).getFv2() !=null
                            ? cementFluids.get(i).getFv2() : "-" ));
                    cementFluidDto.setInjectVol(cementFluidDto.getInjectVol() + " & "  + (cementFluids.get(i).getInjectVol() !=null
                            ? cementFluids.get(i).getInjectVol() : "-" ));
                    cementFluidDto.setIsolatedWaterVol(cementFluidDto.getIsolatedWaterVol() + " & "  + (cementFluids.get(i).getIsolatedWaterVol() !=null
                            ? cementFluids.get(i).getIsolatedWaterVol() : "-" ));
                }
            }
            tmpOutput.setCementFluid(cementFluidDto);

            // 15.领浆 需要拼接
            FluidFirstOutputDto fluidFirstDto = new FluidFirstOutputDto();
            List<CM_WK_FluidFirst> fluidFirsts = cmWkFluidFisrtRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            for (int i = 0; i < fluidFirsts.size(); i++) {
                //不断相加
                if (i == 0) {

                    fluidFirstDto.setFluidType("" + (StringUtils.isNotBlank(fluidFirsts.get(i).getFluidType())
                            ? fluidFirsts.get(i).getFluidType() : "-"));
                    fluidFirstDto.setNo("" + (StringUtils.isNotBlank(fluidFirsts.get(i).getNo())
                            ? fluidFirsts.get(i).getNo() : "-"));
                    fluidFirstDto.setBegin("" + (fluidFirsts.get(i).getBegin() != null
                            ? fluidFirsts.get(i).getBegin() : "-"));
                    fluidFirstDto.setEnd("" + (fluidFirsts.get(i).getEnd() != null
                            ? fluidFirsts.get(i).getEnd() : "-"));
                    fluidFirstDto.setExcessVol("" + (fluidFirsts.get(i).getExcessVol() != null
                            ? fluidFirsts.get(i).getExcessVol() : "-"));
                    fluidFirstDto.setDensity("" + (fluidFirsts.get(i).getDensity() != null
                            ? fluidFirsts.get(i).getDensity() : "-"));
                    fluidFirstDto.setInjectVol("" + (fluidFirsts.get(i).getInjectVol() != null
                            ? fluidFirsts.get(i).getInjectVol() : "-"));
                    fluidFirstDto.setCementVol("" + (fluidFirsts.get(i).getCementVol() != null
                            ? fluidFirsts.get(i).getCementVol() : "-"));
                    fluidFirstDto.setMixWaterVol("" + (fluidFirsts.get(i).getMixWaterVol() != null
                            ? fluidFirsts.get(i).getMixWaterVol() : "-"));
                    fluidFirstDto.setDisplacementVol("" + (fluidFirsts.get(i).getDisplacementVol() != null
                            ? fluidFirsts.get(i).getDisplacementVol() : "-"));
                    fluidFirstDto.setPumpPressure("" + (fluidFirsts.get(i).getPumpPressure() != null
                            ? fluidFirsts.get(i).getPumpPressure() : "-"));
                } else{
                    fluidFirstDto.setFluidType(fluidFirstDto.getFluidType() + " & " + (StringUtils.isNotBlank(fluidFirsts.get(i).getFluidType())
                            ? fluidFirsts.get(i).getFluidType() : "-"));
                    fluidFirstDto.setNo(fluidFirstDto.getNo() + " & " + (StringUtils.isNotBlank(fluidFirsts.get(i).getNo())
                            ? fluidFirsts.get(i).getNo() : "-"));
                    fluidFirstDto.setBegin(fluidFirstDto.getBegin() + " & " + (fluidFirsts.get(i).getBegin() != null
                            ? fluidFirsts.get(i).getBegin() : "-"));
                    fluidFirstDto.setEnd(fluidFirstDto.getEnd() + " & " + (fluidFirsts.get(i).getEnd() != null
                            ? fluidFirsts.get(i).getEnd() : "-"));
                    fluidFirstDto.setExcessVol(fluidFirstDto.getExcessVol() + " & " + (fluidFirsts.get(i).getExcessVol() != null
                            ? fluidFirsts.get(i).getExcessVol() : "-"));
                    fluidFirstDto.setDensity(fluidFirstDto.getDensity() + " & " + (fluidFirsts.get(i).getDensity() != null
                            ? fluidFirsts.get(i).getDensity() : "-"));
                    fluidFirstDto.setInjectVol(fluidFirstDto.getInjectVol() + " & " + (fluidFirsts.get(i).getInjectVol() != null
                            ? fluidFirsts.get(i).getInjectVol() : "-"));
                    fluidFirstDto.setCementVol(fluidFirstDto.getCementVol() + " & " + (fluidFirsts.get(i).getCementVol() != null
                            ? fluidFirsts.get(i).getCementVol() : "-"));
                    fluidFirstDto.setMixWaterVol(fluidFirstDto.getMixWaterVol() + " & " + (fluidFirsts.get(i).getMixWaterVol() != null
                            ? fluidFirsts.get(i).getMixWaterVol() : "-"));
                    fluidFirstDto.setDisplacementVol(fluidFirstDto.getDisplacementVol() + " & " + (fluidFirsts.get(i).getDisplacementVol() != null
                            ? fluidFirsts.get(i).getDisplacementVol() : "-"));
                    fluidFirstDto.setPumpPressure(fluidFirstDto.getPumpPressure() + " & " + (fluidFirsts.get(i).getPumpPressure() != null
                            ? fluidFirsts.get(i).getPumpPressure() : "-"));
                }
            }
            tmpOutput.setFluidFirst(fluidFirstDto);

            // 16.中间液
            Optional<CM_WK_FluidMiddle> fluidMiddleOpt = cmWkFluidMiddleRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (fluidMiddleOpt.isPresent()){
                tmpOutput.setFluidMiddle(fluidMiddleOpt.get());
            }

            // 17.尾浆 需要拼接
            FluidLastOutputDto fluidLastDto = new FluidLastOutputDto();
            List<CM_WK_FluidLast> fluidLasts = cmWkFluidLastRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            for (int i = 0; i < fluidLasts.size(); i++) {
                //不断相加
                if (i == 0) {
                    fluidLastDto.setNo("" + (StringUtils.isNotBlank(fluidLasts.get(i).getNo())
                                    ? fluidLasts.get(i).getNo() : "-" ));
                    fluidLastDto.setBegin("" + (fluidLasts.get(i).getBegin() !=null
                                    ? fluidLasts.get(i).getBegin() : "-" ));
                    fluidLastDto.setEnd("" + (fluidLasts.get(i).getEnd() !=null
                                    ? fluidLasts.get(i).getEnd() : "-" ));
                    fluidLastDto.setExcessVol("" + (fluidLasts.get(i).getExcessVol() !=null
                                    ? fluidLasts.get(i).getExcessVol() : "-" ));
                    fluidLastDto.setDensity("" + (fluidLasts.get(i).getDensity() !=null
                                    ? fluidLasts.get(i).getDensity() : "-" ));
                    fluidLastDto.setInjectVol("" + (fluidLasts.get(i).getInjectVol() !=null
                                    ? fluidLasts.get(i).getInjectVol() : "-" ));
                    fluidLastDto.setCementVol("" + (fluidLasts.get(i).getCementVol() !=null
                                    ? fluidLasts.get(i).getCementVol() : "-" ));
                    fluidLastDto.setMixWaterVol("" + (fluidLasts.get(i).getMixWaterVol() !=null
                                    ? fluidLasts.get(i).getMixWaterVol() : "-" ));
                    fluidLastDto.setDisplacementVol("" + (fluidLasts.get(i).getDisplacementVol() !=null
                                    ? fluidLasts.get(i).getDisplacementVol() : "-" ));
                    fluidLastDto.setPumpPressure("" + (fluidLasts.get(i).getPumpPressure() !=null
                                    ? fluidLasts.get(i).getPumpPressure() : "-" ));
                }else{
                    fluidLastDto.setNo(fluidLastDto.getNo() + " & " + (StringUtils.isNotBlank(fluidLasts.get(i).getNo())
                            ? fluidLasts.get(i).getNo() : "-" ));
                    fluidLastDto.setBegin(fluidLastDto.getBegin() + " & " + (fluidLasts.get(i).getBegin() !=null
                            ? fluidLasts.get(i).getBegin() : "-" ));
                    fluidLastDto.setEnd(fluidLastDto.getEnd() + " & " + (fluidLasts.get(i).getEnd() !=null
                            ? fluidLasts.get(i).getEnd() : "-" ));
                    fluidLastDto.setExcessVol(fluidLastDto.getExcessVol() + " & " + (fluidLasts.get(i).getExcessVol() !=null
                            ? fluidLasts.get(i).getExcessVol() : "-" ));
                    fluidLastDto.setDensity(fluidLastDto.getDensity() + " & " + (fluidLasts.get(i).getDensity() !=null
                            ? fluidLasts.get(i).getDensity() : "-" ));
                    fluidLastDto.setInjectVol(fluidLastDto.getInjectVol() + " & " + (fluidLasts.get(i).getInjectVol() !=null
                            ? fluidLasts.get(i).getInjectVol() : "-" ));
                    fluidLastDto.setCementVol(fluidLastDto.getCementVol() + " & " + (fluidLasts.get(i).getCementVol() !=null
                            ? fluidLasts.get(i).getCementVol() : "-" ));
                    fluidLastDto.setMixWaterVol(fluidLastDto.getMixWaterVol() + " & " + (fluidLasts.get(i).getMixWaterVol() !=null
                            ? fluidLasts.get(i).getMixWaterVol() : "-" ));
                    fluidLastDto.setDisplacementVol(fluidLastDto.getDisplacementVol() + " & " + (fluidLasts.get(i).getDisplacementVol() !=null
                            ? fluidLasts.get(i).getDisplacementVol() : "-" ));
                    fluidLastDto.setPumpPressure(fluidLastDto.getPumpPressure() + " & " + (fluidLasts.get(i).getPumpPressure() !=null
                            ? fluidLasts.get(i).getPumpPressure() : "-" ));
                }
            }
            tmpOutput.setFluidLast(fluidLastDto);

            // 18.顶替过程 cmWkDisplaceDataRepository
            // 12.6 需要拼接
            DisplaceDataOutputDto displaceDataOutputDto = new DisplaceDataOutputDto();
            List<CM_WK_DisplaceData> displaceDataList = cmWkDisplaceDataRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            for (int i = 0; i < displaceDataList.size(); i++){
                displaceDataOutputDto.setCasingSize(displaceDataList.get(i).getCasingSize());
                // 多条通过 & 拼接
                if(i ==0){
                    displaceDataOutputDto.setDisplacementType("" + (StringUtils.isNotBlank(displaceDataList.get(i).getDisplacementType())
                                    ? displaceDataList.get(i).getDisplacementType() : "-" ));
                    displaceDataOutputDto.setDisplacementFluid("" + (StringUtils.isNotBlank(displaceDataList.get(i).getDisplacementFluid())
                                    ? displaceDataList.get(i).getDisplacementFluid() : "-" ));
                    displaceDataOutputDto.setDisplacementVol("" + (displaceDataList.get(i).getDisplacementVol() !=null
                                    ? displaceDataList.get(i).getDisplacementVol() : "-" ));
                    displaceDataOutputDto.setReplaceVolDesign("" + (displaceDataList.get(i).getReplaceVolDesign() !=null
                                    ? displaceDataList.get(i).getReplaceVolDesign() : "-" ));
                    displaceDataOutputDto.setReplaceVolActual("" + (displaceDataList.get(i).getReplaceVolActual() !=null
                                    ? displaceDataList.get(i).getReplaceVolActual() : "-" ));
                    displaceDataOutputDto.setPumpPressure("" + (displaceDataList.get(i).getPumpPressure() !=null
                                    ? displaceDataList.get(i).getPumpPressure() : "-" ));
                    displaceDataOutputDto.setReturnVolLog("" + (displaceDataList.get(i).getReturnVolLog() !=null
                                    ? displaceDataList.get(i).getReturnVolLog() : "-" ));
                    displaceDataOutputDto.setReturnVolDesign("" + (displaceDataList.get(i).getReturnVolDesign() !=null
                                    ? displaceDataList.get(i).getReturnVolDesign() : "-" ));
                    displaceDataOutputDto.setReturnVolTheory("" + (displaceDataList.get(i).getReturnVolTheory() !=null
                                    ? displaceDataList.get(i).getReturnVolTheory() : "-" ));
                }else {
                    displaceDataOutputDto.setDisplacementType(displaceDataOutputDto.getDisplacementType() + " & " + (StringUtils.isNotBlank(displaceDataList.get(i).getDisplacementType())
                            ? displaceDataList.get(i).getDisplacementType() : "-" ));
                    displaceDataOutputDto.setDisplacementFluid(displaceDataOutputDto.getDisplacementFluid() + " & " + (StringUtils.isNotBlank(displaceDataList.get(i).getDisplacementFluid())
                            ? displaceDataList.get(i).getDisplacementFluid() : "-" ));
                    displaceDataOutputDto.setDisplacementVol(displaceDataOutputDto.getDisplacementVol() + " & " + (displaceDataList.get(i).getDisplacementVol() !=null
                            ? displaceDataList.get(i).getDisplacementVol() : "-" ));
                    displaceDataOutputDto.setReplaceVolDesign(displaceDataOutputDto.getReplaceVolDesign() + " & " + (displaceDataList.get(i).getReplaceVolDesign() !=null
                            ? displaceDataList.get(i).getReplaceVolDesign() : "-" ));
                    displaceDataOutputDto.setReplaceVolActual(displaceDataOutputDto.getReplaceVolActual() + " & " + (displaceDataList.get(i).getReplaceVolActual() !=null
                            ? displaceDataList.get(i).getReplaceVolActual() : "-" ));
                    displaceDataOutputDto.setPumpPressure(displaceDataOutputDto.getPumpPressure() + " & " + (displaceDataList.get(i).getPumpPressure() !=null
                            ? displaceDataList.get(i).getPumpPressure() : "-" ));
                    displaceDataOutputDto.setReturnVolLog(displaceDataOutputDto.getReturnVolLog() + " & " + (displaceDataList.get(i).getReturnVolLog() !=null
                            ? displaceDataList.get(i).getReturnVolLog() : "-" ));
                    displaceDataOutputDto.setReturnVolDesign(displaceDataOutputDto.getReturnVolDesign() + " & " + (displaceDataList.get(i).getReturnVolDesign() !=null
                            ? displaceDataList.get(i).getReturnVolDesign() : "-" ));
                    displaceDataOutputDto.setReturnVolTheory(displaceDataOutputDto.getReturnVolTheory() + " & " + (displaceDataList.get(i).getReturnVolTheory() !=null
                            ? displaceDataList.get(i).getReturnVolTheory() : "-" ));
                }
            }
            tmpOutput.setDisplaceData(displaceDataOutputDto);

            // 19.固井顶替 CM_WK_DisplaceRepository
            Optional<CM_WK_Displace> displaceOpt = cmWkDisplaceRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (displaceOpt.isPresent()){
                tmpOutput.setDisplace(displaceOpt.get());
            }

            // 20.返出流体
            Optional<CM_WK_ReturnFluid> returnFluidOpt = cmWkReturnFluidRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (returnFluidOpt.isPresent()){
                tmpOutput.setReturnFluid(returnFluidOpt.get());
            }

            // 21.尾管顶部清洗
            Optional<CM_WK_TailClear> tailClearOpt = cmWkTailClearRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (tailClearOpt.isPresent()){
                tmpOutput.setTailClear(tailClearOpt.get());
            }

            // 22.当量比重
            Optional<CM_WK_Emw> emwOpt = cmWkEmwRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (emwOpt.isPresent()){
                tmpOutput.setEmw(emwOpt.get());
            }

            // 23.复杂情况 cmWkComplexRepository
            // TODO: 12.6 需要拼接
            ComplexOutputDto complexDto = new ComplexOutputDto();
            List<CM_WK_Complex> complexList = cmWkComplexRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            for (int i = 0; i < complexList.size(); i++){
                // 多条通过 & 拼接
                if(i ==0){
                    complexDto.setComplexType("" + (StringUtils.isNotBlank(complexList.get(i).getComplexType())
                                    ? complexList.get(i).getComplexType() : "-" ));
                    complexDto.setDescription("" + (StringUtils.isNotBlank(complexList.get(i).getDescription())
                                    ? complexList.get(i).getDescription() : "-" ));
                }else {
                    complexDto.setComplexType(complexDto.getComplexType() + " & " + (StringUtils.isNotBlank(complexList.get(i).getComplexType())
                            ? complexList.get(i).getComplexType() : "-" ));
                    complexDto.setDescription(complexDto.getDescription() + " & " + (StringUtils.isNotBlank(complexList.get(i).getDescription())
                            ? complexList.get(i).getDescription() : "-" ));
                }
            }
            tmpOutput.setComplex(complexDto);

            // 24.流体评价
            // 需要拼接
            FluidEvalueOutputDto fluidValueDto = new FluidEvalueOutputDto();
            List<CM_WK_FluidValue> fluidValues = cmWkFluidValueRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            for (int i = 0; i < fluidValues.size(); i++) {
                //不断相加
                if (i == 0) {
                    fluidValueDto.setFluidType("" + (StringUtils.isNotBlank(fluidValues.get(i).getFluidType())
                                    ? fluidValues.get(i).getFluidType() : "-" ));
                    fluidValueDto.setNo("" + (fluidValues.get(i).getNo() !=null
                                    ? fluidValues.get(i).getNo() : "-" ));
                    fluidValueDto.setLogBeginDepth("" + (StringUtils.isNotBlank(fluidValues.get(i).getLogBeginDepth())
                                    ? fluidValues.get(i).getLogBeginDepth() : "-" ));
                    fluidValueDto.setLogEndDepth("" + (fluidValues.get(i).getLogEndDepth() !=null
                                    ? fluidValues.get(i).getLogEndDepth() : "-" ));
                    fluidValueDto.setLogVol("" + (fluidValues.get(i).getLogVol() !=null
                                    ? fluidValues.get(i).getLogVol() : "-" ));
                    fluidValueDto.setLogUnitVol("" + (fluidValues.get(i).getLogUnitVol() !=null
                                    ? fluidValues.get(i).getLogUnitVol() : "-" ));
                    fluidValueDto.setRealBeginDepth("" + (fluidValues.get(i).getRealBeginDepth() !=null
                                    ? fluidValues.get(i).getRealBeginDepth() : "-" ));
                    fluidValueDto.setRealEndDepth("" + (fluidValues.get(i).getRealEndDepth() !=null
                                    ? fluidValues.get(i).getRealEndDepth() : "-" ));
                    fluidValueDto.setRealVol("" + (fluidValues.get(i).getRealVol() !=null
                                    ? fluidValues.get(i).getRealVol() : "-"));
                    fluidValueDto.setRealUnitVol("" + (fluidValues.get(i).getRealUnitVol() !=null
                                    ? fluidValues.get(i).getRealUnitVol() : "-"));
                    fluidValueDto.setLogExcessVol("" + (fluidValues.get(i).getLogExcessVol() !=null
                                    ? fluidValues.get(i).getLogExcessVol() : "-"));
                    fluidValueDto.setTheroyExcessVol("" + (fluidValues.get(i).getTheroyExcessVol() !=null
                                    ? fluidValues.get(i).getTheroyExcessVol() : "-"));
                    fluidValueDto.setLogAfterBeginDepth("" + (fluidValues.get(i).getLogAfterBeginDepth() !=null
                                    ? fluidValues.get(i).getLogAfterBeginDepth() : "-"));
                    fluidValueDto.setLogAfterEndDepth("" + (fluidValues.get(i).getLogAfterEndDepth() !=null
                                    ? fluidValues.get(i).getLogAfterEndDepth() : "-"));
                    fluidValueDto.setLogAfterVol("" + (fluidValues.get(i).getLogAfterVol() !=null
                                    ? fluidValues.get(i).getLogAfterVol() : "-"));
                    fluidValueDto.setLogAfterUnitVol("" + (fluidValues.get(i).getLogAfterUnitVol() !=null
                                    ? fluidValues.get(i).getLogAfterUnitVol() : "-"));
                    fluidValueDto.setBestExcessVol("" + (fluidValues.get(i).getBestExcessVol() !=null
                                    ? fluidValues.get(i).getBestExcessVol() : "-"));
                }else{
                    fluidValueDto.setFluidType(fluidValueDto.getFluidType() + " & " + (StringUtils.isNotBlank(fluidValues.get(i).getFluidType())
                            ? fluidValues.get(i).getFluidType() : "-" ));
                    fluidValueDto.setNo(fluidValueDto.getNo() + " & " + (fluidValues.get(i).getNo() !=null
                            ? fluidValues.get(i).getNo() : "-" ));
                    fluidValueDto.setLogBeginDepth(fluidValueDto.getLogBeginDepth() + " & " + (StringUtils.isNotBlank(fluidValues.get(i).getLogBeginDepth())
                            ? fluidValues.get(i).getLogBeginDepth() : "-" ));
                    fluidValueDto.setLogEndDepth(fluidValueDto.getLogEndDepth() + " & " + (fluidValues.get(i).getLogEndDepth() !=null
                            ? fluidValues.get(i).getLogEndDepth() : "-" ));
                    fluidValueDto.setLogVol(fluidValueDto.getLogVol() + " & " + (fluidValues.get(i).getLogVol() !=null
                            ? fluidValues.get(i).getLogVol() : "-" ));
                    fluidValueDto.setLogUnitVol(fluidValueDto.getLogUnitVol() + " & " + (fluidValues.get(i).getLogUnitVol() !=null
                            ? fluidValues.get(i).getLogUnitVol() : "-" ));
                    fluidValueDto.setRealBeginDepth(fluidValueDto.getRealBeginDepth() + " & " + (fluidValues.get(i).getRealBeginDepth() !=null
                            ? fluidValues.get(i).getRealBeginDepth() : "-" ));
                    fluidValueDto.setRealEndDepth(fluidValueDto.getRealEndDepth() + " & " + (fluidValues.get(i).getRealEndDepth() !=null
                            ? fluidValues.get(i).getRealEndDepth() : "-" ));
                    fluidValueDto.setRealVol(fluidValueDto.getRealVol() + " & " + (fluidValues.get(i).getRealVol() !=null
                            ? fluidValues.get(i).getRealVol() : "-"));
                    fluidValueDto.setRealUnitVol(fluidValueDto.getRealUnitVol() + " & " + (fluidValues.get(i).getRealUnitVol() !=null
                            ? fluidValues.get(i).getRealUnitVol() : "-"));
                    fluidValueDto.setLogExcessVol(fluidValueDto.getLogExcessVol() + " & " + (fluidValues.get(i).getLogExcessVol() !=null
                            ? fluidValues.get(i).getLogExcessVol() : "-"));
                    fluidValueDto.setTheroyExcessVol(fluidValueDto.getTheroyExcessVol() + " & " + (fluidValues.get(i).getTheroyExcessVol() !=null
                            ? fluidValues.get(i).getTheroyExcessVol() : "-"));
                    fluidValueDto.setLogAfterBeginDepth(fluidValueDto.getLogAfterBeginDepth() + " & " + (fluidValues.get(i).getLogAfterBeginDepth() !=null
                            ? fluidValues.get(i).getLogAfterBeginDepth() : "-"));
                    fluidValueDto.setLogAfterEndDepth(fluidValueDto.getLogAfterEndDepth() + " & " + (fluidValues.get(i).getLogAfterEndDepth() !=null
                            ? fluidValues.get(i).getLogAfterEndDepth() : "-"));
                    fluidValueDto.setLogAfterVol(fluidValueDto.getLogAfterVol() + " & " + (fluidValues.get(i).getLogAfterVol() !=null
                            ? fluidValues.get(i).getLogAfterVol() : "-"));
                    fluidValueDto.setLogAfterUnitVol(fluidValueDto.getLogAfterUnitVol() + " & " + (fluidValues.get(i).getLogAfterUnitVol() !=null
                            ? fluidValues.get(i).getLogAfterUnitVol() : "-"));
                    fluidValueDto.setBestExcessVol(fluidValueDto.getBestExcessVol() + " & " + (fluidValues.get(i).getBestExcessVol() !=null
                            ? fluidValues.get(i).getBestExcessVol() : "-"));
                }
            }
            tmpOutput.setFluidValue(fluidValueDto);

            // 25.井口回注 cmWkWellRejectRepository
            Optional<CM_WK_WellReject> wellRejectOpt = cmWkWellRejectRepository.findByWellNameAndCasingSize(tmpWellName, tmpCasingSize);
            if (wellRejectOpt.isPresent()) {
                tmpOutput.setWellReject(wellRejectOpt.get());
            }

            output.add(tmpOutput);
        }

        return R.ok().putData(output);
    }

}
